#ifndef COLORMAP_H
#define COLORMAP_H

#include <map>

#include "src/core/generic/vector3.h"
#include "src/core/scene/material.h"

// VizMf ColorMap class
// now linear interpolation only!

#include <QDebug>

class ColorMap
{
private:
  typedef std::map<double, Material> float_container_type;
  typedef std::pair<double, Material> pair;
public:
  ColorMap()
  {
    addReference( 99999999999999.9, Material(0.0, 0.0, 0.0, 0.0));
    addReference(-99999999999999.9, Material(0.0, 0.0, 0.0, 0.0));
  }
  void addReference(const double v, const Material& m)
  {
    float_points.insert(pair(v, m));
  }
  Material operator [](const double v) const
  {
    float_container_type::const_iterator l = float_points.upper_bound(v), u = l--;
    return l->second.interpolate(u->second, (v - l->first)/(u->first - l->first));
//    return l->second + (u->second - l->second) / (u->first - l->first) * (v - l.first);
  }
  static ColorMap defaultBlueToRed()
  {
    ColorMap map;
    map.addReference(1.0, Material(0.0, 1.0, 1.0, 1.0));
    map.addReference(0.0000000001, Material(0.0, 1.0, 1.0, 1.0));
    map.addReference(-0.0000000001, Material(1.0, 0.0, 0.0, 1.0));
    map.addReference(-1.0, Material(1.0, 0.0, 0.0, 1.0));
    return map;
  }

private:
  float_container_type float_points;
};

#endif // COLORMAP_H
